import 'package:flutter_deer/account/models/bank_entity.dart';

import 'package:flutter_deer/generated/json/bank_entity.g.dart';

import 'package:flutter_deer/account/models/city_entity.dart';

import 'package:flutter_deer/generated/json/city_entity.g.dart';

import 'package:flutter_deer/goods/models/goods_sort_entity.dart';

import 'package:flutter_deer/generated/json/goods_sort_entity.g.dart';

import 'package:flutter_deer/order/models/search_entity.dart';

import 'package:flutter_deer/generated/json/search_entity.g.dart';

import 'package:flutter_deer/shop/models/user_entity.dart';

import 'package:flutter_deer/generated/json/user_entity.g.dart';

import 'package:flutter_deer/index/models/play_entity.dart';

import 'package:flutter_deer/generated/json/play_entity.g.dart';

import 'package:flutter_deer/account/models/user_bank_entity.dart';

import 'package:flutter_deer/generated/json/user_bank_entity.g.dart';

import 'package:flutter_deer/account/models/flowing_water_entity.dart';

import 'package:flutter_deer/shop/models/agent_user_entity.dart';

import 'package:flutter_deer/account/models/take_out_entity.dart';

import 'package:flutter_deer/generated/json/take_out_entity.g.dart';

import 'package:flutter_deer/generated/json/withdraw_password_entity.g.dart';

import 'package:flutter_deer/account/models/withdraw_password_entity.dart';

import 'package:flutter_deer/index/models/banner_entity.dart';

import 'package:flutter_deer/index/models/football_ratio_entity.dart';

import 'package:flutter_deer/generated/json/football_ratio_entity.g.dart';

import 'package:flutter_deer/login/models/register_user_entity.dart';

import 'package:flutter_deer/generated/json/register_user_entity.g.dart';

import 'package:flutter_deer/index/models/user_betting_entity.dart';

import 'package:flutter_deer/generated/json/user_betting_entity.g.dart';

import 'package:flutter_deer/generated/json/game_item_entity.g.dart';

import 'package:flutter_deer/game/models/game_item_entity.dart';

import 'package:flutter_deer/generated/json/user_score_deposit_entity.g.dart';

import 'package:flutter_deer/account/models/user_score_deposit_entity.dart';

import 'package:flutter_deer/generated/json/user_score_takeout_entity.g.dart';

import 'package:flutter_deer/account/models/user_score_takeout_entity.dart';

import 'package:flutter_deer/account/models/account_summary_entity.dart';

import 'package:flutter_deer/generated/json/account_summary_entity.g.dart';

import 'package:flutter_deer/generated/json/version_entity.g.dart';

import 'package:flutter_deer/setting/models/version_entity.dart';

import 'package:flutter_deer/account/models/agent_user_betting_entity.dart';
import 'package:flutter_deer/index/models/indicator_document_entity.dart';
import 'package:flutter_deer/index/models/capital_comparison_entity.dart';
import 'package:flutter_deer/index/models/historical_expenditure_entity.dart';
import 'package:flutter_deer/index/models/expenditure_progress_entity.dart';
import 'package:flutter_deer/index/models/com_code_entity.dart';
import 'package:flutter_deer/generated/json/agent_user_betting_entity.g.dart';
import 'package:flutter_deer/generated/json/indicator_document_entity.g.dart';
import 'package:flutter_deer/generated/json/historical_expenditure_entity.g.dart';
import 'package:flutter_deer/generated/json/expenditure_progress_entity.g.dart';
import 'package:flutter_deer/generated/json/capital_comparison_entity.g.dart';
import 'package:flutter_deer/generated/json/com_code_entity.g.dart';
import 'package:flutter_deer/net/base_entity.dart';

JsonConvert jsonConvert = JsonConvert();

class JsonConvert {
  T? convert<T>(dynamic value) {
    if (value == null) {
      return null;
    }

    return asT<T>(value);
  }

  List<T?>? convertList<T>(List<dynamic>? value) {
    if (value == null) {
      return null;
    }

    try {
      return value.map((dynamic e) => asT<T>(e)).toList();
    } catch (e, stackTrace) {
      print('asT<$T> $e $stackTrace');

      return <T>[];
    }
  }

  List<T>? convertListNotNull<T>(dynamic value) {
    if (value == null) {
      return null;
    }

    try {
      return (value as List<dynamic>).map((dynamic e) => asT<T>(e)!).toList();
    } catch (e, stackTrace) {
      print('asT<$T> $e $stackTrace');

      return <T>[];
    }
  }

  T? asT<T extends Object?>(dynamic value) {
    if (value is T) {
      return value;
    }

    final String type = T.toString();

    try {
      final String valueS = value.toString();

      if (type == "String") {
        return valueS as T;
      } else if (type == "int") {
        final int? intValue = int.tryParse(valueS);

        if (intValue == null) {
          return double.tryParse(valueS)?.toInt() as T?;
        } else {
          return intValue as T;
        }
      } else if (type == "double") {
        return double.parse(valueS) as T;
      } else if (type == "DateTime") {
        return DateTime.parse(valueS) as T;
      } else if (type == "bool") {
        if (valueS == '0' || valueS == '1') {
          return (valueS == '1') as T;
        }

        return (valueS == 'true') as T;
      } else {
        return JsonConvert.fromJsonAsT<T>(value);
      }
    } catch (e, stackTrace) {
      print('asT<$T> $e $stackTrace');

      return null;
    }
  }

  //Go back to a single instance by type

  static M? _fromJsonSingle<M>(Map<String, dynamic> json) {
    final String type = M.toString();

    if (type == (BaseEntity<UserBettingResultEntity>).toString()) {
      return BaseEntity<UserBettingResultEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<FocusMapDetailEntity>).toString()) {
      return BaseEntity<FocusMapDetailEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<UserBettingDetailEntity>).toString()) {
      return BaseEntity<UserBettingDetailEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<UserBettingSearchEntity>).toString()) {
      return BaseEntity<UserBettingSearchEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<AgentUserBettingSummaryEntity>).toString()) {
      return BaseEntity<AgentUserBettingSummaryEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<GameItemEntity>).toString()) {
      return BaseEntity<GameItemEntity>.fromJson(json) as M;
    }

    if (type ==
        (BaseEntity<BelowUserScoreDepositStatisticsEntity>).toString()) {
      return BaseEntity<BelowUserScoreDepositStatisticsEntity>.fromJson(json)
          as M;
    }

    if (type ==
        (BaseEntity<BelowUserScoreTakeoutStatisticsEntity>).toString()) {
      return BaseEntity<BelowUserScoreTakeoutStatisticsEntity>.fromJson(json)
          as M;
    }

    if (type == (BaseEntity<BelowUserScoreDepositPageEntity>).toString()) {
      return BaseEntity<BelowUserScoreDepositPageEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<BelowUserScoreTakeoutPageEntity>).toString()) {
      return BaseEntity<BelowUserScoreTakeoutPageEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<UserBettingPageEntity>).toString()) {
      return BaseEntity<UserBettingPageEntity>.fromJson(json) as M;
    }
    if (type == (BaseEntity<IndicatorDocumentPageEntity>).toString()) {
      return BaseEntity<IndicatorDocumentPageEntity>.fromJson(json) as M;
    }
    if (type == (BaseEntity<List<IndicatorDocumentEntity>>).toString()) {
      return BaseEntity<List<IndicatorDocumentEntity>>.fromJson(json) as M;
    }
    if (type == (BaseEntity<List<CodeMapEntity>>).toString()) {
      return BaseEntity<List<CodeMapEntity>>.fromJson(json) as M;
    }
    if (type == (BaseEntity<CapitalComparisonPageEntity>).toString()) {
      return BaseEntity<CapitalComparisonPageEntity>.fromJson(json) as M;
    }
    if (type == (BaseEntity<List<CapitalComparisonEntity>>).toString()) {
      return BaseEntity<List<CapitalComparisonEntity>>.fromJson(json) as M;
    }
    if (type == (BaseEntity<HistoricalExpenditurePageEntity>).toString()) {
      return BaseEntity<HistoricalExpenditurePageEntity>.fromJson(json) as M;
    }
    if (type == (BaseEntity<List<HistoricalExpenditureEntity>>).toString()) {
      return BaseEntity<List<HistoricalExpenditureEntity>>.fromJson(json) as M;
    }
        if (type == (BaseEntity<ExpenditureProgressPageEntity>).toString()) {
      return BaseEntity<ExpenditureProgressPageEntity>.fromJson(json) as M;
    }
    if (type == (BaseEntity<List<ExpenditureProgressEntity>>).toString()) {
      return BaseEntity<List<ExpenditureProgressEntity>>.fromJson(json) as M;
    }
    if (type == (BaseEntity<List<FootballGameEntity>>).toString()) {
      return BaseEntity<List<FootballGameEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<FileUploadEntity>).toString()) {
      return BaseEntity<FileUploadEntity>.fromJson(json) as M;
    }

    // if (type == (BaseEntity<BaseApiDataEntity>).toString()) {

    //   return BaseEntity<BaseApiDataEntity>.fromJson(json) as M;

    // }

    if (type == (BaseEntity<RegisterUserEntity>).toString()) {
      return BaseEntity<RegisterUserEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<FootballRatioGroupEntity>>).toString()) {
      return BaseEntity<List<FootballRatioGroupEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<FootballRatioGroupEntity>).toString()) {
      return BaseEntity<FootballRatioGroupEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<BannerEntity>).toString()) {
      return BaseEntity<BannerEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<BannerEntity>>).toString()) {
      return BaseEntity<List<BannerEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<bool>).toString()) {
      return BaseEntity<bool>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<TakeOutEntity>>).toString()) {
      return BaseEntity<List<TakeOutEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<AgentUserEntity>>).toString()) {
      return BaseEntity<List<AgentUserEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<AgentUserBettingSummaryEntity>>).toString()) {
      return BaseEntity<List<AgentUserBettingSummaryEntity>>.fromJson(json)
          as M;
    }

    if (type == (BaseEntity<AgentUserEntity>).toString()) {
      return BaseEntity<AgentUserEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<GameItemPageEntity>).toString()) {
      return BaseEntity<GameItemPageEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<UserScoreDepositPageEntity>).toString()) {
      return BaseEntity<UserScoreDepositPageEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<UserScoreDepositEntity>).toString()) {
      return BaseEntity<UserScoreDepositEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<UserScoreTakeoutPageEntity>).toString()) {
      return BaseEntity<UserScoreTakeoutPageEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<UserScoreTakeoutEntity>).toString()) {
      return BaseEntity<UserScoreTakeoutEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<UserInfoEntity>).toString()) {
      return BaseEntity<UserInfoEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<UserBankEntity>).toString()) {
      return BaseEntity<UserBankEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<UserBettingEntity>).toString()) {
      return BaseEntity<UserBettingEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<BankEntity>>).toString()) {
      return BaseEntity<List<BankEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<UserBankEntity>>).toString()) {
      return BaseEntity<List<UserBankEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<FlowingWaterEntity>>).toString()) {
      return BaseEntity<List<FlowingWaterEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<FlowingWaterItemEntity>>).toString()) {
      return BaseEntity<List<FlowingWaterItemEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<FootballGameUnstartEntity>>).toString()) {
      return BaseEntity<List<FootballGameUnstartEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<List<GameItemEntity>>).toString()) {
      return BaseEntity<List<GameItemEntity>>.fromJson(json) as M;
    }

    if (type == (BaseEntity<AccountSummaryEntity>).toString()) {
      return BaseEntity<AccountSummaryEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<FootballGameUnstartEntity>).toString()) {
      return BaseEntity<FootballGameUnstartEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<VersionEntity>).toString()) {
      return BaseEntity<VersionEntity>.fromJson(json) as M;
    }

    if (type == (BaseEntity<AgentUserBettingSummaryPoolEntity>).toString()) {
      return BaseEntity<AgentUserBettingSummaryPoolEntity>.fromJson(json) as M;
    }

    if (type == (FocusMapDetailEntity).toString()) {
      return FocusMapDetailEntity.fromJson(json) as M;
    }

    if (type == (UserBettingSearchEntity).toString()) {
      return UserBettingSearchEntity.fromJson(json) as M;
    }

    if (type == (AgentUserBettingParamEntity).toString()) {
      return AgentUserBettingParamEntity.fromJson(json) as M;
    }

    if (type == (VersionEntity).toString()) {
      return VersionEntity.fromJson(json) as M;
    }

    if (type == (FootballGameUnstartEntity).toString()) {
      return FootballGameUnstartEntity.fromJson(json) as M;
    }

    if (type == (FootballGameRatioEntity).toString()) {
      return FootballGameRatioEntity.fromJson(json) as M;
    }

    if (type == (AccountSummaryEntity).toString()) {
      return AccountSummaryEntity.fromJson(json) as M;
    }

    if (type == (UserScoreDepositEntity).toString()) {
      return UserScoreDepositEntity.fromJson(json) as M;
    }

    if (type == (BelowUserScoreDepositStatisticsEntity).toString()) {
      return BelowUserScoreDepositStatisticsEntity.fromJson(json) as M;
    }

    if (type == (BelowUserScoreTakeoutStatisticsEntity).toString()) {
      return BelowUserScoreTakeoutStatisticsEntity.fromJson(json) as M;
    }

    if (type == (BelowUserScoreDepositPageEntity).toString()) {
      return BelowUserScoreDepositPageEntity.fromJson(json) as M;
    }

    if (type == (BelowUserScoreTakeoutPageEntity).toString()) {
      return BelowUserScoreTakeoutPageEntity.fromJson(json) as M;
    }

    if (type == (UserScoreDepositPageEntity).toString()) {
      return UserScoreDepositPageEntity.fromJson(json) as M;
    }

    if (type == (UserScoreTakeoutEntity).toString()) {
      return UserScoreTakeoutEntity.fromJson(json) as M;
    }

    if (type == (UserBettingResultEntity).toString()) {
      return UserBettingResultEntity.fromJson(json) as M;
    }

    if (type == (UserBettingDetailEntity).toString()) {
      return UserBettingDetailEntity.fromJson(json) as M;
    }

    if (type == (UserScoreTakeoutPageEntity).toString()) {
      return UserScoreTakeoutPageEntity.fromJson(json) as M;
    }

    if (type == (AgentUserBettingSummaryEntity).toString()) {
      return AgentUserBettingSummaryEntity.fromJson(json) as M;
    }

    if (type == (FileUploadEntity).toString()) {
      return FileUploadEntity.fromJson(json) as M;
    }

    // if (type == (BaseApiDataEntity).toString()) {

    //   return BaseApiDataEntity.fromJson(json) as M;

    // }

    if (type == (OperatorBaseEntity).toString()) {
      return OperatorBaseEntity.fromJson(json) as M;
    }

    if (type == (DoubleBaseEntity).toString()) {
      return DoubleBaseEntity.fromJson(json) as M;
    }

    if (type == (StringBaseEntity).toString()) {
      return StringBaseEntity.fromJson(json) as M;
    }

    if (type == (GameItemEntity).toString()) {
      return GameItemEntity.fromJson(json) as M;
    }

    if (type == (GameItemPageEntity).toString()) {
      return GameItemPageEntity.fromJson(json) as M;
    }

    if (type == (UserBettingEntity).toString()) {
      return UserBettingEntity.fromJson(json) as M;
    }

    if (type == (WithdrawPasswordEntity).toString()) {
      return WithdrawPasswordEntity.fromJson(json) as M;
    }

    if (type == (UserBankEntity).toString()) {
      return UserBankEntity.fromJson(json) as M;
    }

    if (type == (BankEntity).toString()) {
      return BankEntity.fromJson(json) as M;
    }

    if (type == (CityEntity).toString()) {
      return CityEntity.fromJson(json) as M;
    }

    if (type == (GoodsSortEntity).toString()) {
      return GoodsSortEntity.fromJson(json) as M;
    }

    if (type == (UserBettingPageEntity).toString()) {
      return UserBettingPageEntity.fromJson(json) as M;
    }
    if (type == (IndicatorDocumentPageEntity).toString()) {
      return IndicatorDocumentPageEntity.fromJson(json) as M;
    }
    if (type == (CapitalComparisonPageEntity).toString()) {
      return CapitalComparisonPageEntity.fromJson(json) as M;
    }
    if (type == (ExpenditureProgressPageEntity).toString()) {
      return ExpenditureProgressPageEntity.fromJson(json) as M;
    }
    if (type == (HistoricalExpenditurePageEntity).toString()) {
      return HistoricalExpenditurePageEntity.fromJson(json) as M;
    }
    if (type == (SearchEntity).toString()) {
      return SearchEntity.fromJson(json) as M;
    }

    if (type == (SearchItems).toString()) {
      return SearchItems.fromJson(json) as M;
    }

    if (type == (SearchItemsOwner).toString()) {
      return SearchItemsOwner.fromJson(json) as M;
    }

    if (type == (SearchItemsLicense).toString()) {
      return SearchItemsLicense.fromJson(json) as M;
    }

    if (type == (UserEntity).toString()) {
      return UserEntity.fromJson(json) as M;
    }

    if (type == (UserInfoEntity).toString()) {
      return UserInfoEntity.fromJson(json) as M;
    }

    if (type == (UserTokenEntity).toString()) {
      return UserTokenEntity.fromJson(json) as M;
    }

    if (type == (PlayItems).toString()) {
      return PlayItems.fromJson(json) as M;
    }

    if (type == (PlayRatioItems).toString()) {
      return PlayRatioItems.fromJson(json) as M;
    }

    if (type == (FootballRatioGroupEntity).toString()) {
      return FootballRatioGroupEntity.fromJson(json) as M;
    }

    if (type == (FootballRatioEntity).toString()) {
      return FootballRatioEntity.fromJson(json) as M;
    }

    if (type == (FootballGameEntity).toString()) {
      return FootballGameEntity.fromJson(json) as M;
    }

    if (type == (FootballTeamEntity).toString()) {
      return FootballTeamEntity.fromJson(json) as M;
    }

    if (type == (UserAvatarEntity).toString()) {
      return UserAvatarEntity.fromJson(json) as M;
    }

    if (type == (AgentUserBettingSummaryPoolEntity).toString()) {
      return AgentUserBettingSummaryPoolEntity.fromJson(json) as M;
    }

    if (type == (AgentUserBettingSummaryEntity).toString()) {
      return AgentUserBettingSummaryEntity.fromJson(json) as M;
    }

    print("$type not found");

    return null;
  }

  //list is returned by type

  static M? _getListChildType<M>(List<dynamic> data) {
    if (<String>[] is M) {
      return data.map<String>((e) => e.toString()).toList() as M;
    }

    if (<UserBettingDetailEntity>[] is M) {
      return data
          .map<UserBettingDetailEntity>(
              (e) => UserBettingDetailEntity.fromJson(e))
          .toList() as M;
    }

    if (<AgentUserBettingSummaryEntity>[] is M) {
      return data
          .map<AgentUserBettingSummaryEntity>(
              (e) => AgentUserBettingSummaryEntity.fromJson(e))
          .toList() as M;
    }

    if (<BelowUserScoreDepositEntity>[] is M) {
      return data
          .map<BelowUserScoreDepositEntity>(
              (e) => BelowUserScoreDepositEntity.fromJson(e))
          .toList() as M;
    }


    if (<BelowUserScoreTakeoutEntity>[] is M) {
      return data
          .map<BelowUserScoreTakeoutEntity>(
              (e) => BelowUserScoreTakeoutEntity.fromJson(e))
          .toList() as M;
    }

    if (<TakeOutEntity>[] is M) {
      return data.map<TakeOutEntity>((e) => TakeOutEntity.fromJson(e)).toList()
          as M;
    }

    if (<UserBettingEntity>[] is M) {
      return data
          .map<UserBettingEntity>((e) => UserBettingEntity.fromJson(e))
          .toList() as M;
    }

    if (<FootballGameEntity>[] is M) {
      return data
          .map<FootballGameEntity>((e) => FootballGameEntity.fromJson(e))
          .toList() as M;
    }

    if (<IndicatorDocumentEntity>[] is M) {
      return data
          .map<IndicatorDocumentEntity>(
              (e) => IndicatorDocumentEntity.fromJson(e))
          .toList() as M;
    }
    if (<CodeMapEntity>[] is M) {
      return data
          .map<CodeMapEntity>(
              (e) => CodeMapEntity.fromJson(e))
          .toList() as M;
    }
    if (<HistoricalExpenditureEntity>[] is M) {
      return data
          .map<HistoricalExpenditureEntity>(
              (e) => HistoricalExpenditureEntity.fromJson(e))
          .toList() as M;
    }
    if (<ExpenditureProgressEntity>[] is M) {
      return data
          .map<ExpenditureProgressEntity>(
              (e) => ExpenditureProgressEntity.fromJson(e))
          .toList() as M;
    }
    if (<CapitalComparisonEntity>[] is M) {
      return data
          .map<CapitalComparisonEntity>(
              (e) => CapitalComparisonEntity.fromJson(e))
          .toList() as M;
    }
    if (<FootballRatioGroupEntity>[] is M) {
      return data
          .map<FootballRatioGroupEntity>(
              (e) => FootballRatioGroupEntity.fromJson(e))
          .toList() as M;
    }

    if (<FootballRatioEntity>[] is M) {
      return data
          .map<FootballRatioEntity>((e) => FootballRatioEntity.fromJson(e))
          .toList() as M;
    }

    if (<BannerEntity>[] is M) {
      return data.map<BannerEntity>((e) => BannerEntity.fromJson(e)).toList()
          as M;
    }

    if (<AgentUserEntity>[] is M) {
      return data
          .map<AgentUserEntity>((e) => AgentUserEntity.fromJson(e))
          .toList() as M;
    }

    if (<UserScoreDepositEntity>[] is M) {
      return data
          .map<UserScoreDepositEntity>(
              (e) => UserScoreDepositEntity.fromJson(e))
          .toList() as M;
    }

    if (<UserScoreTakeoutEntity>[] is M) {
      return data
          .map<UserScoreTakeoutEntity>(
              (e) => UserScoreTakeoutEntity.fromJson(e))
          .toList() as M;
    }

    if (<FlowingWaterEntity>[] is M) {
      return data
          .map<FlowingWaterEntity>((e) => FlowingWaterEntity.fromJson(e))
          .toList() as M;
    }

    if (<FlowingWaterItemEntity>[] is M) {
      return data
          .map<FlowingWaterItemEntity>(
              (e) => FlowingWaterItemEntity.fromJson(e))
          .toList() as M;
    }

    if (<BankEntity>[] is M) {
      return data.map<BankEntity>((e) => BankEntity.fromJson(e)).toList() as M;
    }

    if (<UserBankEntity>[] is M) {
      return data
          .map<UserBankEntity>((e) => UserBankEntity.fromJson(e))
          .toList() as M;
    }

    if (<FootballGameUnstartEntity>[] is M) {
      return data
          .map<FootballGameUnstartEntity>(
              (e) => FootballGameUnstartEntity.fromJson(e))
          .toList() as M;
    }

    if (<CityEntity>[] is M) {
      return data.map<CityEntity>((e) => CityEntity.fromJson(e)).toList() as M;
    }

    if (<GoodsSortEntity>[] is M) {
      return data
          .map<GoodsSortEntity>((e) => GoodsSortEntity.fromJson(e))
          .toList() as M;
    }

    if (<SearchEntity>[] is M) {
      return data.map<SearchEntity>((e) => SearchEntity.fromJson(e)).toList()
          as M;
    }

    if (<SearchItems>[] is M) {
      return data.map<SearchItems>((e) => SearchItems.fromJson(e)).toList()
          as M;
    }

    if (<SearchItemsOwner>[] is M) {
      return data
          .map<SearchItemsOwner>((e) => SearchItemsOwner.fromJson(e))
          .toList() as M;
    }

    if (<SearchItemsLicense>[] is M) {
      return data
          .map<SearchItemsLicense>((e) => SearchItemsLicense.fromJson(e))
          .toList() as M;
    }

    if (<UserEntity>[] is M) {
      return data.map<UserEntity>((e) => UserEntity.fromJson(e)).toList() as M;
    }

    if (<PlayItems>[] is M) {
      return data.map<PlayItems>((e) => PlayItems.fromJson(e)).toList() as M;
    }

    if (<PlayRatioItems>[] is M) {
      return data
          .map<PlayRatioItems>((e) => PlayRatioItems.fromJson(e))
          .toList() as M;
    }

    if (<GameItemEntity>[] is M) {
      return data
          .map<GameItemEntity>((e) => GameItemEntity.fromJson(e))
          .toList() as M;
    }

    print("${M.toString()} not found");

    return null;
  }

  static M? fromJsonAsT<M>(dynamic json) {
    if (json == null) {
      return null;
    }

    if (json is List) {
      return _getListChildType<M>(json);
    } else {
      return _fromJsonSingle<M>(json as Map<String, dynamic>);
    }
  }
}
